<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>消息</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Cache-Control" content="no-transform">
		<meta name="format-detection" content="telephone=no">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" href="style/css/basic.css">
		<link rel="stylesheet" href="style/css/my.css" />
		<script type="text/javascript" src="style/plugin/mui/js/mui.min.js"></script>
		<script type="text/javascript" src="style/js/jquery-1.8.3.min.js" ></script>
		<script type="text/javascript" src="style/mockjs/dist/mock.js"></script>
		<script type="text/javascript" src="style/js/vue.min.js"></script>
		<script type="text/javascript" src="style/js/vue-resource.js"></script>
		<script type="text/javascript" src="style/js/basic.js"></script>
	</head>
	<body>
		<div id="myNews">
		    <!--header-->
			<div id="header">
				<h1>消息</h1>
				<span class="backicon"></span>
			</div>
			<!--content-->
			<div class="body" id="refreshContainer">
				<ul class="listli my_message">
					<li @tap="jumpNewsDetail(index)" v-for="(news,index) in myNewsList">
						<a href="javascript:;" :class="news.type==1?redPoint:''">
							<span>{{news.content}}</span>
							<span>{{fTime(news.create_time)}}</span>
						</a>
					</li>
					<!--<li>
						<a href="javascript:;">
							<span>您有新的核销记录通知</span>
							<span>2018-07-28 12:46</span>
						</a>
					</li>-->
				</ul>
			</div>	
		</div>
		<script>
			new Vue({
				el:"#myNews",
				data:{
					flag:[],
					myNewsList:"",
					ticket:"",
				    sign:"",
				    redPoint:"red_point"
				},
				methods:{
					jumpNewsDetail:function(nIndex){
						this.flag[nIndex]=false;
						var newId=this.myNewsList[nIndex].id;
						var that=this;
						mui.plusReady(function(){
							openurl_can('message_details',newId)
						})
					},
					fTime:function(timestamp){
	                	if (typeof timestamp == "undefined") {
					        timestamp = Math.round(new Date().getTime() / 1000)
					    }
					    var n = parseInt(timestamp) * 1000
					    var date = new Date(n);
					    var Y = date.getFullYear() + '-';
					    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
					    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
					    var H=date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
					    var Min=date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
					    var S=date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
					    return (Y + M + D)
	                }
				},
				created:function(){
					this.ticket=localStorage.getItem("tick")
                    this.sign=localStorage.getItem("sig")
					//请求我的消息
//					this.$http.post(domain+"/member_msg/getList?t="+this.ticket+"&sign="+this.sign,{emulateJSON:true}).then( 
//			            function (res) {
//			                // 处理成功的结果
//			                if(res.body.code==1){
//			                  console.log(res.body)	
//			                  this.myNewsList=res.body.data.list;  
////			                  for(var i in res.body.data){
////			                  	this.flag[i]=true
////			                  }
//			                } 
//			            },function (res) {
//			            // 处理失败的结果 
//			            console.log(res) 
//			            }
//			        );
				},
				mounted:function(){
					var p=1;
					var that=this; 
					mui.plusReady(function(){
						mui.init({
						  pullRefresh : {
						    container:"#refreshContainer",
						    down : {
						      style:'circle',
						      color:'#2BD009', 
						      height:'50px',
						      range:'100px', 
						      offset:'0px', 
						      contentdown:null,
						      auto: true,
						      callback :pullrefesh  	      
						    }
						  }
						}); 
					})
					function pullrefesh(){
						that.$http.post(domain+"/member_msg/getList",{
					      	page_id:p++,
					      	page_size:7 
					      },{emulateJSON:true}).then(
				            function (res) {
				                // 处理成功的结果
				                console.log(res.body)
				                if(res.body.code==1){
				                	if(res.body.data.length==0){
					                	mui.toast("没有更多了")
					                	return false;
					                  }
				                    that.myNewsList=res.body.data.list; 
				                }else{
				                	mui.toast("暂无商品")
				                }
				            },function (res) {
				            // 处理失败的结果
				            console.log(res)  
				            }
				        ).then(function(){
				        	mui('#refreshContainer').pullRefresh().endPulldownToRefresh();   
				        });
						
					} 
				}
			})
		</script>
	</body>
</html>
